<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\model\learn\book;

use app\api\model\Order as OrderModel;
use app\api\service\User as UserService;
use app\common\model\learn\book\Note as NoteModel;
use cores\exception\BaseException;
use think\facade\Db;

/**
 *
 * Class Note
 * @package app\api\model
 */
class Note extends NoteModel {
	/**
	 * 隐藏字段
	 * @var array
	 */
	protected $hidden = [
		'user_id',

		'store_id',
		'is_delete',
		'update_time',
	];

	/**
	 * 获取指定商品评价列表
	 * @param int $goodsId 商品ID
	 * @param int|null $scoreType 评分 (10好评 20中评 30差评)
	 * @return \think\Paginator
	 * @throws \think\db\exception\DbException
	 */
	public function getList($params) {
		$userId = UserService::getCurrentLoginUserId();

		$filter = $this->getFilter($params);
		$list = $this->where($filter)
			->where('user_id', $userId)
			->order(['create_time' => 'desc'])
			->select()->toArray();

		// 加载商品评价的关联数据
		return $list;
	}
	public function remove(): bool {
	
	
		return $this->delete();
	}
	/**
	 * 获取查询条件
	 * @param int $goodsId 商品ID
	 * @param int|null $scoreType 评分 (10好评 20中评 30差评)
	 * @return array[]
	 */
	private function getFilter($params): array {
		// 筛选条件
		$filter = [
			['article_id', '=', $params['articleId']],
			['status', '=', 1],
			['is_delete', '=', 0],
		];

		return $filter;
	}

	/**
	 * 添加评论
	 * @param OrderModel $order
	 * @param $goodsList
	 * @param array $data
	 * @return boolean
	 * @throws BaseException
	 */
	public function add(array $data): bool {

		$data['user_id'] = UserService::getCurrentLoginUserId();
		$data['store_id'] = self::$storeId;
		$this->save($data);

		return true;

	}
	public function edit(array $data): bool {

		$this->save($data);

		return true;

	}

}
